home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Applications / ircle 1.5.1 / source / ircle sources / IRCSComm.p < prev    next >
Encoding:
Text File  |  1993-11-15  |  6.7 KB  |  245 lines  |  [TEXT/PJMM]

  1. {    ircle - Internet Relay Chat client    }
  2. {    File: IRCSComm    }
  3. {    Copyright © 1992 Olaf Titz (s_titz@ira.uka.de)    }
  4.  
  5. {    This program is free software; you can redistribute it and/or modify    }
  6. {    it under the terms of the GNU General Public License as published by    }
  7. {    the Free Software Foundation; either version 2 of the License, or    }
  8. {    (at your option) any later version.    }
  9.  
  10. {    This program is distributed in the hope that it will be useful,    }
  11. {    but WITHOUT ANY WARRANTY; without even the implied warranty of    }
  12. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    }
  13. {    GNU General Public License for more details.    }
  14.  
  15. {    You should have received a copy of the GNU General Public License    }
  16. {    along with this program; if not, write to the Free Software    }
  17. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    }
  18.  
  19. unit IRCSComm;
  20. { Handles messages and commands from server }
  21.  
  22. interface
  23. uses
  24.     TCPTypes, TCPStuff, TCPConnections, ApplBase, MiscGlue, MsgWindows, IRCGlobals,{}
  25.     IRCAux, IRCPreferences, IRCChannels, CTCP, IRCCommands, IRCNComm,{}
  26.     IRCNotify, IRCIgnore;
  27.  
  28. procedure ServerCommands (var s: string);
  29. { Handle command line got from server }
  30.  
  31. implementation
  32.  
  33. procedure ServerCommands (var s: string);
  34.     var
  35.         i: integer;
  36.         ign: boolean;
  37.         from, target, comm: string[40];
  38.         fromuser: string[60];
  39.         st: string;
  40.         dd: MWHndl;
  41.     begin
  42.         st := '';
  43.         if s[1] = ':' then begin
  44.             i := pos(' ', s);
  45.             fromuser := copy(s, 2, i - 2);
  46.             delete(s, 1, i);
  47.         end
  48.         else
  49.             fromuser := '';
  50.         NextArg(s, comm);
  51.         i := pos(' ', s);
  52.         if i = 0 then
  53.             target := ''
  54.         else begin
  55.             target := copy(s, 1, i - 1);
  56.             delete(s, 1, i)
  57.         end;
  58.         ign := IsIgnored(fromuser, (comm <> 'NOTICE'));
  59.         i := pos('!', fromuser); { nick!user@host -> nick }
  60.         if i > 0 then begin
  61.             from := copy(fromuser, 1, i - 1);
  62.             delete(fromuser, 1, i)
  63.         end
  64.         else begin
  65.             from := fromuser;
  66.             fromuser := '';
  67.         end;
  68.         if s[1] = ':' then
  69.             delete(s, 1, 1);
  70.  
  71.         if (comm[1] >= '0') and (comm[1] <= '9') then begin
  72. {the following line will decode an exact-3-digit-number...}
  73.             if not NumericComm(ord(comm[1]) * 100 + ord(comm[2]) * 10 + ord(comm[3]) - 5328, from, target, s) then begin
  74.                 flushing := false;
  75.             end
  76.             else
  77.                 st := 'NUM';
  78.         end
  79. { These are the commands sent to the client as defined in the IRCII and 2.7 server sources. }
  80. { Commands obsoleted by 2.7 are taken out! }
  81.         else if comm = 'NOTICE' then
  82.             if ign then
  83.                 st := 'I'
  84.             else begin
  85.                 doCTCP(from, target, s, true);
  86.                 if s = '' then
  87.                     st := 'CTCP'
  88.                 else begin
  89.                     begin
  90.                         if (from = '') or (from = CurrentServer) then
  91.                             st := s
  92.                         else begin
  93.                             if CurrentServer = '' then begin
  94.                                 CurrentServer := from;
  95.                                 st := s
  96.                             end
  97.                             else
  98.                                 st := concat('-', from, '- ', s);
  99.                         end;
  100.                         if IsChannel(target) then
  101.                             ChannelMsg(target, st)
  102.                         else
  103.                             ChannelMsg(from, st);
  104.                     end
  105.                 end
  106.             end
  107.         else if comm = 'PRIVMSG' then
  108.             if ign then
  109.                 st := 'I'
  110.             else begin
  111.                 doCTCP(from, target, s, false);
  112.                 if s = '' then
  113.                     st := 'CTCP'
  114.                 else begin
  115.                     if IsChannel(target) then begin
  116.                         st := concat('<', from, '> ', s);    { Public message }
  117.                         ChannelMsg(target, st);
  118.                     end
  119.                     else if equalstring(target, currentNick, false, true) then begin
  120.                         st := concat('*', from, '* ', s);    { Private message }
  121.                         ChannelMsg(from, st);
  122.                         lastMSG := from;
  123.                     end
  124.                     else begin
  125.                         st := concat('(', from, ')', s);    { possibly bogus? }
  126.                         Message(s);
  127.                     end
  128.                 end
  129.             end
  130.         else if comm = 'JOIN' then begin
  131.             if EqualString(from, CurrentNick, false, true) then begin
  132.                 currentTarget := s;
  133.                 dd := DoJoin(currentTarget);
  134.                 st := concat('MODE ', s);
  135.                 HandleCommand(st);
  136.                 st := 'J';
  137.             end
  138.             else begin
  139.                 OneNotify(from, true);
  140.                 if fromuser = '' then
  141.                     st := concat('*** ', from, ' has joined ', s)
  142.                 else
  143.                     st := concat('*** ', from, ' [', fromuser, '] has joined ', s);
  144.                 lastMSG := from;
  145.                 if ShowJOIN then
  146.                     ChannelMsg(s, st)
  147.             end
  148.         end
  149.         else if comm = 'PART' then begin
  150.             if from = currentNick then begin
  151.                 st := s;
  152.                 DoPart(st)
  153.             end
  154.             else begin
  155.                 st := concat('*** ', from, ' has left ', s);
  156.                 if ShowPART then
  157.                     ChannelMsg(s, st);
  158.             end
  159.         end
  160.         else if comm = 'QUIT' then begin { is special in that it has no target par }
  161.             OneNotify(from, false);
  162.             if target <> '' then begin
  163.                 if target[1] = ':' then
  164.                     delete(target, 1, 1);
  165.                 target := concat(target, ' ')
  166.             end;
  167.             st := concat('*** Signoff: ', from, ' (', target, s, ')');
  168.             if ShowQUIT then
  169.                 Message(st);
  170.         end
  171.         else if comm = 'WALLOPS' then begin
  172.             st := concat('!', from, '! ', s);
  173.             if ShowWALLOPS then
  174.                 LineMsg(st);
  175.         end
  176.         else if comm = 'PING' then begin
  177.             st := concat('PONG ', default^^.userloginname, ' ', s);
  178.             HandleCommand(st);
  179.             st := 'PONG'
  180.         end
  181.         else if comm = 'TOPIC' then begin
  182.             st := concat(from, ' has set the topic on ', target, ' to ', s);
  183.             if showTOPIC then
  184.                 ChannelMsg(target, st)
  185.         end
  186.         else if comm = 'PONG' then begin
  187.             st := concat('*** Got PONG from ', from);
  188.             Message(st);
  189.         end
  190.         else if comm = 'INVITE' then begin
  191.             st := concat('*** ', from, ' invites ', target, ' to channel ', s);
  192.             lastInvite := s;
  193.             if ShowINVITE then
  194.                 ChannelMsg(s, st)
  195.         end
  196.         else if comm = 'NICK' then begin
  197.             if EqualString(from, CurrentNick, false, true) then begin
  198.                 CurrentNick := s;
  199.                 SetMainTitle(CurrentNick);
  200.             end;
  201.             OneNotify(from, false);
  202.             OneNotify(s, true);
  203.             st := concat('*** ', from, ' is now known as ', s);
  204.             if ShowNICK then
  205.                 Message(st)
  206.         end
  207.         else if comm = 'KILL' then begin
  208.             if pos('.', from) > 0 then begin { server kill }
  209.                 st := concat('*** You have been rejected by ', from, ' (', s, ')');
  210.                 LineMsg(st);
  211.             end
  212.             else begin { operator kill: display alert box & quit }
  213. { Incompletely tested; maybe the path gets too long and the reason isn't displayed }
  214.                 paramtext(from, s, '', '');
  215.                 i := Alert(A_OPKILL, nil);
  216.                 QuitRequest := true
  217.             end;
  218.         end
  219.         else if comm = 'MODE' then begin
  220.             st := concat(from, ' changed the mode on ', target, ' to "', s, '"');
  221.             if ShowMODE then
  222.                 ChannelMsg(target, st);
  223.         end
  224.         else if comm = 'KICK' then begin
  225.             if EqualString(s, CurrentNick, false, true) then begin
  226.                 st := concat('*** You have been kicked from ', target, ' by ', from);
  227.                 ChannelMsg(target, st);
  228.                 Inactive(target);
  229.             end
  230.             else begin
  231.                 st := concat(from, ' kicked ', s, ' from ', target);
  232.                 if ShowKICK then
  233.                     ChannelMsg(target, st)
  234.             end
  235.         end
  236.         else if (comm = 'ERROR') or (comm = 'ERROR:') then begin {the : form honors buggy servers }
  237.             st := concat('*** (', from, ') ', target, ' ', s)
  238.         end;
  239.         if st = '' then begin { Display unprocessed commands. }
  240.             st := concat('/', comm, '/', from, '/', target, '/', s, '/');
  241.             LineMsg(st);
  242.         end;
  243.     end;
  244.  
  245. end.